{% load i18n %}
{% load bootstrap3 %}
{% load static %}
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link rel="shortcut icon" href="{{ FAVICON_URL }}" type="image/x-icon">
    <title>
        {{ JMS_TITLE }}
    </title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- Stylesheets -->
    <link href="{% static 'css/bootstrap.min.css' %}" rel="stylesheet">
    <link href="{% static 'css/font-awesome.min.css' %}" rel="stylesheet">
    <link href="{% static 'css/bootstrap-style.css' %}" rel="stylesheet">
    <link href="{% static 'css/login-style.css' %}" rel="stylesheet">
    <link href="{% static 'css/style.css' %}" rel="stylesheet">
    <link href="{% static 'css/jumpserver.css' %}" rel="stylesheet">

    <!-- scripts -->
    <script src="{% static 'js/jquery-3.1.1.min.js' %}"></script>
    <script src="{% static 'js/plugins/sweetalert/sweetalert.min.js' %}"></script>
    <script src="{% static 'js/bootstrap.min.js' %}"></script>
    <script src="{% static 'js/plugins/datatables/datatables.min.js' %}"></script>

    <style>
        .login-content {
            box-shadow: 0 5px 5px -3px rgb(0 0 0 / 20%), 0 8px 10px 1px rgb(0 0 0 / 14%), 0 3px 14px 2px rgb(0 0 0 / 12%);
        }

        .help-block {
            margin: 0;
            text-align: left;
        }

        form label {
            color: #737373;
            font-size: 13px;
            font-weight: normal;
        }

        .hr-line-dashed {
            border-top: 1px dashed #e7eaec;
            color: #ffffff;
            background-color: #ffffff;
            height: 1px;
            margin: 20px 0;
        }

        .login-content {
            height: 472px;
            width: 984px;
            margin-right: auto;
            margin-left: auto;
            margin-top: calc((100vh - 470px) / 3);
        }
        body {
            background-color: #f2f2f2;
            height: calc(100vh - (100vh - 470px) / 3);
        }

        .right-image-box {
            height: 100%;
            width: 50%;
            float: right;
        }

        .left-form-box {
            text-align: center;
            background-color: white;
            height: 100%;
            width: 50%;
        }

        .captcha {
            float: right;
        }

        .red-fonts {
            color: red;
        }

        .field-error {
            text-align: left;
        }

        .form-group.has-error {
            margin-bottom: 0;
        }

        .captch-field .has-error .help-block {
            margin-top: -8px !important;
        }

        .no-captcha-challenge .form-group {
            margin-bottom: 20px;
        }

        .jms-title {
            padding: 40px 10px 10px;
        }

        .no-captcha-challenge .jms-title {
            padding: 60px 10px 10px;
        }

        .no-captcha-challenge .welcome-message {
            padding-top: 10px;
        }

        .radio, .checkbox {
            margin: 0;
        }

        #github_star {
            float: right;
            margin: 10px 10px 0 0;
        }
        .more-login-item {
            border-right: 1px dashed #dedede;
            padding-left: 5px;
            padding-right: 5px;
        }

        .more-login-item:last-child {
            border: none;
        }

    </style>
</head>

<body>
<div class="login-content ">
    <div class="right-image-box">
        <a href="{% if not XPACK_ENABLED %}https://github.com/jumpserver/jumpserver{% endif %}">
            <img src="{{ LOGIN_IMAGE_URL }}" style="height: 100%; width: 100%"/>
        </a>
    </div>
    <div class="left-form-box {% if not form.challenge and not form.captcha %} no-captcha-challenge {% endif %}">
        <div style="background-color: white">
            <div class="jms-title">
                <span style="font-size: 21px;font-weight:400;color: #151515;letter-spacing: 0;">{{ JMS_TITLE }}</span>
            </div>
            <div class="contact-form col-md-10 col-md-offset-1">
                <form id="login-form" action="" method="post" role="form" novalidate="novalidate">
                    {% csrf_token %}
                    <div style="line-height: 17px;margin-bottom: 20px;color: #999999;">
                    {% if form.errors %}
                        <p class="red-fonts" style="color: red">
                            {% if form.non_field_errors %}
                                {{ form.non_field_errors.as_text }}
                            {% endif %}
                        </p>
                    {% else %}
                        <p class="welcome-message">
                            {% trans 'Welcome back, please enter username and password to login' %}
                        </p>
                    {% endif %}
                    </div>

                    {% bootstrap_field form.username show_label=False %}
                    <div class="form-group">
                        <input type="password" class="form-control" id="password" placeholder="{% trans 'Password' %}" required="">
                        <input id="password-hidden" type="text" style="display:none" name="{{ form.password.html_name }}">
                    </div>
                    {% if form.challenge %}
                        {% bootstrap_field form.challenge show_label=False %}
                    {% elif form.captcha %}
                        <div class="captch-field">
                            {% bootstrap_field form.captcha show_label=False %}
                        </div>
                    {% endif %}
                    <div class="form-group" style="padding-top: 5px; margin-bottom: 10px">
                        <div class="row">
                            <div class="col-md-6" style="text-align: left">
                                {% if form.auto_login %}
                                    {% bootstrap_field form.auto_login form_group_class='' %}
                                {% endif %}
                            </div>
                            <div class="col-md-6">
                                <a id="forgot_password" href="{{ forgot_password_url }}" style="float: right">
                                    <small>{% trans 'Forgot password' %}?</small>
                                </a>
                            </div>
                        </div>
                    </div>

                    <div class="form-group" style="">
                        <button type="submit" class="btn btn-transparent" onclick="doLogin();return false;">{% trans 'Login' %}</button>
                    </div>

                    <div>
                        {% if AUTH_OPENID or AUTH_CAS or AUTH_WECOM or AUTH_DINGTALK %}
                            <div class="hr-line-dashed"></div>
                            <div style="display: inline-block; float: left">
                                <b class="text-muted text-left" >{% trans "More login options" %}</b>
                                {% if AUTH_OPENID %}
                                    <a href="{% url 'authentication:openid:login' %}" class="more-login-item">
                                        <i class="fa fa-openid"></i> {% trans 'OpenID' %}
                                    </a>
                                {% endif %}
                                {% if AUTH_CAS %}
                                    <a href="{% url 'authentication:cas:cas-login' %}" class="more-login-item">
                                        <i class="fa"><img src="{{ LOGIN_CAS_LOGO_URL }}" height="13" width="13"></i> {% trans 'CAS' %}
                                    </a>
                                {% endif %}
                                {% if AUTH_WECOM %}
                                    <a href="{% url 'authentication:wecom-qr-login' %}" class="more-login-item">
                                        <i class="fa"><img src="{{ LOGIN_WECOM_LOGO_URL }}" height="13" width="13"></i> {% trans 'WeCom' %}
                                    </a>
                                {% endif %}
                                {% if AUTH_DINGTALK %}
                                    <a href="{% url 'authentication:dingtalk-qr-login' %}" class="more-login-item">
                                        <i class="fa"><img src="{{ LOGIN_DINGTALK_LOGO_URL }}" height="13" width="13"></i> {% trans 'DingTalk' %}
                                    </a>
                                {% endif %}

                            </div>
                        {% else %}
                            <div class="text-center" style="display: inline-block;">
                        {% endif %}
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript" src="/static/js/plugins/jsencrypt/jsencrypt.min.js"></script>
<script>
    function encryptLoginPassword(password, rsaPublicKey) {
        var jsencrypt = new JSEncrypt(); //加密对象
        jsencrypt.setPublicKey(rsaPublicKey); // 设置密钥
        return jsencrypt.encrypt(password); //加密
    }

    function doLogin() {
        //公钥加密
        var rsaPublicKey = "{{ rsa_public_key }}"
        var password = $('#password').val(); //明文密码
        var passwordEncrypted = encryptLoginPassword(password, rsaPublicKey)
        $('#password-hidden').val(passwordEncrypted); //返回给密码输入input
        $('#login-form').submit();//post提交
    }

    $(document).ready(function () {
    })
</script>
</html>

